Distributed Log Store
๐ Overviewโ
This project is a simplified Kafka-like distributed append-only log system built from scratch using Java 23 and Spring Boot.
It demonstrates how high-throughput, ordered writes can be achieved by enforcing single-leader writes per partition, eliminating locks while maintaining correctness, durability, and scalability.
Core idea: Ordering is enforced by a single leader per partition. All writes are append-only and sequential, enabling lock-free, high-performance ingestion.
๐ฏ Goals of the Projectโ
- Understand append-only log architecture
- Learn partitioned concurrency without locks
- Implement leaderโfollower replication
- Demonstrate crash recovery using log replay
- Build a systems-level project, not CRUD
๐ง Key Concepts Implementedโ
| Concept | Description |
|---|---|
| Append-only log | Data is never updated or deleted in place |
| Partitioning | Data is sharded into independent tablets |
| Single leader | One writer per partition ensures ordering |
| Sequential I/O | Disk writes are sequential, not random |
| Offset-based reads | Consumers read using monotonically increasing offsets |
| Replication | Leader replicates log entries to followers |
| Crash recovery | Logs are replayed on startup |
๐๏ธ Architectureโ
High-Level Architecture Diagramโ

---### Component Interaction
โโโโโโโโโโโโโโ
โ Client โ
โโโโโโโฌโโโโโโโ
โ
v
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TabletServer โ
โ (Leader Instance) โ
โโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโ
โ โ
โโโโโโโโโโโโvโโโโ โโโโvโโโโโโโโโโโโ
โ Tablet A โ โ Tablet B โ
โ (Partition) โ โ (Partition) โ
โโโโโโโฌโโโโโโโโโ โโโโโโโฌโโโโโโโโโโ
โ โ
Append-only Log Append-only Log
(Sequential I/O) (Sequential I/O)
โ (gRPC)-high rate โ
โโโโโโโโvโโโโโโโโโ โโโโโโโโvโโโโโโโโโ
โ Replica Server โ โ Replica Server โ
โ (Follower) โ โ (Follower) โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ
Core Architectural Principlesโ
- Each tablet = one partition
- Exactly one leader per tablet
- Only leader writes to the log
- Replication is log-based and ordered
- Concurrency happens across tablets, not within
๐ Why No Locks Are Neededโ
- A tablet has exactly one leader
- Only the leader thread appends to its log
- Offset assignment is a monotonic counter
- No shared mutable state between tablets
Result:
- No race conditions
- No file-level locks
- Extremely high write throughput
๐ Log Record Formatโ
Each log entry is stored sequentially in the following format:
[offset][timestamp][keyLength][key][valueLength][value]
offsetโ Monotonically increasing- Records are immutable
- New entries are appended at the end of the file
Exampleโ
0|1734150400123|user-123|CREATE-TASK 1|1734150400456|user-456|UPDATE-TASK
Records are append-only and written sequentially to disk. Offsets are strictly increasing and never reused.โ
๐ REST APIs Swaggerโ
Append Recordโ
POST /append
{
"key": "user123",
"value": "event-data"
}
Response
{
"tabletId": 2,
"offset": 1042
}
Read Recordโ
GET /read?tabletId=2&offset=1042
๐ Replication Modelโ
-
Each tablet consists of:
- 1 leader
- N replicas
-
Workflow:
- Leader appends record
- Offset is assigned
- Record is replicated to followers
- Followers append in the same order
This guarantees ordering, durability, and fault tolerance.
๐ฅ Crash Recoveryโ
On startup:
- Log files are scanned
- Last offset is recovered
- Appends resume from the correct position
โ No data loss โ No offset duplication โ Safe restarts
๐ Project Structureโ
mini-log-store/
โโโ src/main/java/com/example/logstore
โ โโโ api/
โ โ โโโ AppendController.java
โ โ โโโ ReadController.java
โ โ
โ โโโ server/
โ โ โโโ TabletServer.java
โ โ โโโ LeaderReplicator.java
โ โ โโโ ReplicaReceiver.java
โ โ
โ โโโ tablet/
โ โ โโโ Tablet.java
โ โ โโโ TabletRouter.java
โ โ โโโ TabletRegistry.java
โ โ
โ โโโ storage/
โ โ โโโ AppendOnlyLog.java
โ โ โโโ LogSegment.java
โ โ โโโ LogReader.java
โ โ
โ โโโ recovery/
โ โ โโโ LogReplayService.java
โ โ
โ โโโ MiniLogStoreApplication.java
โ
โโโ src/main/resources/
โ โโโ application.yml
โ
โโโ README.md
โโโ pom.xml
๐ ๏ธ Tech Stackโ
- Java: OpenJDK 23.0.1
- Framework: Spring Boot
- Build Tool: Apache Maven 3.9.11
- I/O: FileChannel for sequential disk writes
- Networking: gRPC for inter-node communication
- Protocol: Client -> REST (HTTP) | Leader - Followers (gRPC)
๐ Performance Characteristicsโ
- Sequential disk writes
- Append-only storage
- No random disk access
- Lock-free write path
- Horizontal scalability via partitions
๐งช What This Project Intentionally Excludesโ
- Raft / Paxos
- Exactly-once semantics
- Transactions
- Schema registry
These are excluded to keep focus on core log storage mechanics.
๐ฎ Future Enhancementsโ
- Log compaction
- Segment rolling
- Read replicas
- Metrics & monitoring
- Leader re-election
๐ Licenseโ
MIT
